package com.wang.common.security.config;

import com.wang.common.security.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 对HTTP请求进行全局拦截,实现统一的认证和授权逻辑
 */
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**") //拦截所有请求
                .excludePathPatterns("/**/login") //排除登录接口
                .excludePathPatterns("/user/sendCode") //排除发送验证码接口
                .excludePathPatterns("/**/semiLogin/**") //排除游客接口

                //排除Knife4j文档接口
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/v3/api-docs/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/doc.html");
    }
}
